﻿using MediatR;
using NPOI.POIFS.Macros;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.BasicInformation;
using THE_WIND_RISES.Common.Domans.BasicInformation.Log;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Application.Commands.Week1.Log_CR
{
    public class ShowUserLogHandler : IRequestHandler<ShowUserLogCommand, Result>
    {
        /// <summary>
        /// 显示日志表数据
        /// </summary>
        /// <param name="userLogRepository"></param>
        public ShowUserLogHandler(IBaseRepository<UserLog> userLogRepository)
        {
            UserLogRepository = userLogRepository;
        }

        public IBaseRepository<UserLog> UserLogRepository { get; set; }
        public async Task<Result> Handle(ShowUserLogCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = new Result() { Code = (int)CommonErrorCodes.Search };
                var sql = "select * from UserLog;";
                var list = UserLogRepository.GetAll(sql).ToList();
                if (list != null)
                {
                    result.Data = list;
                    result.Code = (int)CommonErrorCodes.Success;
                    return result;
                }
                else
                {
                    return result;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
